package com.example.bai2;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

@SuppressLint("NewApi") public class MainActivity extends Activity {
	 static long income=0; 
	 static long visitor=0;
	 static long vip=0;
     
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
      
       final EditText edtName=(EditText) findViewById(R.id.edtName);
       final EditText edtBookAmount=(EditText) findViewById(R.id.edtBookAmount);
       final EditText edtIncome=(EditText) findViewById(R.id.edtIncome);
       final EditText edtVIPVisitorAmount=(EditText) findViewById(R.id.edtVIPVisitorAmount);
       final EditText edtVisitorAmount=(EditText) findViewById(R.id.edtVisitorAmount);
        
        final CheckBox chkVIP=(CheckBox) findViewById(R.id.chkVIP);

        final TextView txtTotal=(TextView) findViewById(R.id.txtTotal);
        
        Button btnThongKe=(Button) findViewById(R.id.btnThongKe);
        Button btnTiep=(Button) findViewById(R.id.btnTiep);
        Button btnTinh=(Button) findViewById(R.id.btnTinh);
        ImageButton btnexit=(ImageButton) findViewById(R.id.btnexit);
       
        btnTinh.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(!edtBookAmount.getText().toString().isEmpty())
				{
					long cost=Long.parseLong(edtBookAmount.getText().toString())*20000;
					if(chkVIP.isChecked())
					{
						cost=(long) (cost*0.9);
					}
					txtTotal.setText(String.valueOf(cost));
				}
					
			}
		});
        btnTiep.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(!txtTotal.getText().toString().isEmpty())
				{
					income=income+Long.parseLong(txtTotal.getText().toString());
					visitor++;
					if(chkVIP.isChecked())
					{
						vip++;
					}
				}
				//clear
				edtName.setText("");
				edtName.requestFocus();
				edtBookAmount.setText("");
				txtTotal.setText("");
			}
		});
        
        btnThongKe.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				edtIncome.setText(String.valueOf(income));
				edtVisitorAmount.setText(String.valueOf(visitor));
				edtVIPVisitorAmount.setText(String.valueOf(vip));
				
				edtIncome.requestFocus();
			}
		});
        
        btnexit.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder bulider=new Builder(MainActivity.this);
				bulider.setTitle("EXIT..");
				bulider.setMessage("ARE YOU SURE??");
				bulider.setPositiveButton("YES", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						finish();
					}
				});
				bulider.setNegativeButton("NO", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.cancel();
					}
				});
				bulider.create().show();
			}
		});
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
